import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_demo/pages/platform.dart';
import 'package:talker_flutter/talker_flutter.dart';

import '../main.dart';

class PageOne extends StatefulWidget {
  const PageOne({super.key});

  @override
  State<PageOne> createState() => _PageOneState();
}

class _PageOneState extends State<PageOne> {
  static const platform =
      MethodChannel('com.trassion.flutterhybirddemo.MyFlutterView');

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        title: "PageOne",
        home: Scaffold(
          appBar: AppBar(
            title: Text("PageOne"),
          ),
          body: Container(
            color: Colors.redAccent,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              children: [
                const Text("PageOne"),
                FilledButton(
                    onPressed: () {
                      platform
                          .invokeMethod('setText', {'name': '张三', 'age': 18});
                    },
                    child: Text("修改原生View的数据")),
                FilledButton(
                    onPressed: () async {
                      var result = await  platform
                          .invokeMethod('getData', {'name': '张三', 'age': 18});
                      talker.info(result);
                      // Navigator.of(context).push(
                      //     MaterialPageRoute(
                      //       builder: (context) => TalkerScreen(talker: talker),
                      //     )
                      // );
                    },
                    child: Text("获取原生数据")),
                (isAndroid() == true)
                    ? const SizedBox(
                        height: 40,
                        child: AndroidView(
                          viewType: 'plugins.flutter.io/custom_platform_view',
                          creationParams: {
                            'text': 'Flutter传给AndroidTextView的参数'
                          },
                          creationParamsCodec: StandardMessageCodec(),
                        ),
                      )
                    : const SizedBox.shrink(),
              ],
            ),
          )
          //   child: (isAndroid() == true)
          //       ? const AndroidView(
          //           viewType: 'plugins.flutter.io/custom_platform_view',
          //           creationParams: {'text': 'Flutter传给AndroidTextView的参数'},
          //           creationParamsCodec: StandardMessageCodec(),
          //         )
          //       : const SizedBox.shrink(),
          // ),
          ,
        ));
  }
}
